package com.cn.wanxi.controller;

import com.cn.wanxi.Result.Result;
import com.cn.wanxi.entity.User;
import com.cn.wanxi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/back/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("add")
    public Result add(User user) {
        return userService.add(user);
    }

    @PostMapping("update")
    public Result update(User user) {
        return userService.update(user);
    }

    @PostMapping("delete")
    public Result delete(User user) {
        return userService.del(user);
    }

    @GetMapping("findById")
    public Result findById(User user) {
        return userService.findById(user);
    }

    @GetMapping("getCount")
    public Result getCount(User user) {
        return userService.getCount(user);
    }

    @CrossOrigin
    @GetMapping("findAll")
    public Result findAll(User user, HttpServletRequest req) {
        ServletContext servletContext = req.getServletContext();
        System.out.println(servletContext);

        return userService.findAll(user);
    }
}
